package love.simbot.example.utils.bilibili;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import love.simbot.example.entity.bilibili.VideoResult;
import love.simbot.example.utils.http.HttpUtils;

import java.util.HashMap;

// BiliBili的Api调用
public abstract class BiliBiliUtils {

    private static final String url = "https://api.linhun.vip/api/bilibilisearch";

    public static VideoResult getVideo(String keywords) throws JsonProcessingException {
        HashMap<String,String> params = new HashMap<>();
        params.put("name",keywords);
        ObjectMapper om = new ObjectMapper();
        om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
        String result = HttpUtils.getTool(url, params);
        VideoResult videoResult = om.readValue(result, VideoResult.class);
        return videoResult;
    }

}
